package com.example.config;

import com.example.interceptor.LogincheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * Interceptor阻拦器的配置文件
 * 一般通Configuration注解来表示该文件为特殊的配置文件
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

  //从Bean容器注入定定义的阻拦器
  @Autowired
  private LogincheckInterceptor logincheckInterceptor;
  //输入自定的阻拦器 规定生效范围 排除在外的链接
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logincheckInterceptor).
                addPathPatterns("/**").excludePathPatterns("/login");
    }
}
